package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.models.HouseInfo;
import com.budwk.app.sqfw.models.PersonInfo;
import com.budwk.app.sqfw.services.HouseInfoService;
import com.budwk.app.sqfwV2.dto.dto.PersonInfoDTO;
import com.budwk.app.sqfwV2.dto.vo.HouseInfoReqVo;
import com.budwk.app.sqfwV2.dto.vo.HouseInfoResVo;
import com.budwk.app.sqfwV2.dto.vo.PersonInfoReqVo;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiFormParams;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.dao.Cnd;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import java.util.List;

@IocBean
@At("/platform/sqfwV2/houseInfo")
@ApiDefinition(tag = "房屋信息api")
@Slf4j
public class HouseInfoController {

    @Inject
    private HouseInfoService houseInfoService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "房屋采集信息提交")
    @ApiFormParams(implementation = HouseInfo.class)
    @SLog(tag = "房屋采集信息提交", value = "${args[0]}")
    @SaCheckLogin
    public Result<HouseInfo> submitData(@Param("..") HouseInfo reqVo) {
        log.info("HouseInfoController submitData param: {}", JSONObject.toJSONString(reqVo));
        return Result.data(houseInfoService.submitData(reqVo));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "查询关联人员信息")
    @SaCheckLogin
    public Result<List<PersonInfo>> listRelatePerson(@Param("..") PersonInfoReqVo reqVo) {
        log.info("HouseInfoController listPersonByHouseId param: {}", JSONObject.toJSONString(reqVo));
        return Result.data(houseInfoService.listRelatePerson(reqVo));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "按照房产查询已经关联的人员信息")
    @SaCheckLogin
    public Result<List<HouseInfo>> listPersonByHouseId(@Param("..") String buildId) {
        return Result.data(houseInfoService.findByBuildId(buildId));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "修改楼层信息接口")
    @ApiFormParams(implementation = HouseInfoReqVo.class)
    @SLog(tag = "修改楼层信息接口", value = "${args[0]}")
    @SaCheckLogin
    public Result<HouseInfo> updateFloor(@Param("..") HouseInfoReqVo dto) {
        log.info("HouseInfoController updateFloor param: {}", JSONObject.toJSONString(dto));
        houseInfoService.updateFloor(dto);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "房屋楼栋信息列表")
    @ApiFormParams(implementation = HouseInfoReqVo.class)
    @SaCheckLogin
    public Result<Pagination> listBuildHouses(@Param("..") HouseInfoReqVo dto) {
        log.info("buildingInfo listByPage param: {}", JSONObject.toJSONString(dto));
        return houseInfoService.listBuildHouses(dto);
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "房屋详情信息列表")
    @SaCheckLogin
    public Result<HouseInfo> listHouseDetail(@Param("houseId") String houseId) {
        return Result.data(houseInfoService.getHouseDetail(houseId));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询所有的房屋信息")
    @SaCheckLogin
    public Result<HouseInfoResVo> listAllHouseByBuildId(@Param("buildingId") String buildingId) {
        return houseInfoService.listAllHouseByBuildId(buildingId);
    }

    @At
    @Ok("json")
    @DELETE
    @ApiOperation(name = "删除房屋信息")
    @ApiFormParams(implementation = HouseInfoReqVo.class)
    @SLog(tag = "删除房屋信息", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> deleteData(@Param("..") HouseInfoReqVo reqVo) {
        log.info("houseInfoService deleteBuilding param: {}", JSONObject.toJSONString(reqVo));
        houseInfoService.deleteData(reqVo);
        return Result.success();
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询所有删除的房屋信息")
    @SaCheckLogin
    public Result<?> queryDeleteData() {
        List<HouseInfo> list = houseInfoService.query(Cnd.where(HouseInfo::isDeleted, "=", true));
        return Result.data(list);
    }
}
